home *** CD-ROM | disk | FTP | other *** search
- Path: newdelph.cig.mot.com!coypu!bhttchry
- From: bhttchry@coypu.cig.mot.com (Soumya Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Query about the #line preprocessor directive
- Date: 25 Mar 1996 12:08:17 GMT
- Organization: Cellular Infrastructure Group, Motorola
- Message-ID: <4j62bh$svj@newdelph.cig.mot.com>
- NNTP-Posting-Host: coypu.cig.mot.com
-
- Dear Readers,
-
- I had implemented an ANSI C preprocessor. I am trying this sample
- program with my preprocessor:
-
- -------------------------
- #line /* This is
- a multiline
- comment
- nicely
- done */ 100
- __LINE__
- --------------------------
-
- The output produced by my preprocessor is:
-
- --------------------------------
- # 1 "1.c"
- /* This is
- a multiline
- comment
- nicely
- done */# 100
- 104
- -------------------------------
-
- Whereas gcc's (ANSI C conformant) preprocessor produces:
-
- ----------------------------------
- # 1 "1.c"
- /* This is
- a multiline
- comment
- nicely
- done */
- # 99 "1.c"
-
- 100
- ---------------------------------
-
-
-
- The thing is that the line containing the #line directive had this
- multiline comment. The ANSI standard book in the section describing #line
- directive says (section 6.8.4)
-
- "... the directive causes the implementation to behave as if
- the following sequence of source lines begins with a source line that
- has a line number as specified by the digit sequence..."
-
- In the same place it defines "line number" as "...one greater
- than the number of new-line characters read or introduced in the
- translation phase..."
-
- In usual cases, multiline comments do indeed cause the source
- line count to get incremented. I felt that the ANSI specification was a
- bit fuzzy in the above situation. The way I interpreted it was that a
- "source line" is a bit different from a "preprocessor directive line"
- -- as seen in the above example, a "preprocessor directive line" can
- indeed span multiple "source lines". Thus, the #line should mean that
- the next _source line_ should have the line number specified in the
- directive: in this case the next source line is a part of the
- directive itself!
-
- Thus, according to my interpretation, my preprocessor is doing
- the right thing.
-
- Do knowledgeable readers agree or disagree? Do you not think
- that ANSI has left this a bit unspecified (so that both my
- preprocessor as well as gcc may be correct depending on the the
- interpretation)?
-
- Kindly send your valuable responses to me by E-mail.
-
-
- Regards,
-
- --
- Soumya
-